package com.blic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.blic.interceptor.TokenInterceptor;
import com.blic.interceptor.WeixinInfoInterceptor;


@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {
	
	
	@Bean
    public WeixinInfoInterceptor getWeixinInfoInterceptor() {
        return new WeixinInfoInterceptor();
    }
	
	@Bean
    public TokenInterceptor getTokenInterceptor() {
        return new TokenInterceptor();
    }
	
	
	@Override
	public void addInterceptors(InterceptorRegistry registry){  
		
		InterceptorRegistration weixinInterceptor = registry.addInterceptor(getWeixinInfoInterceptor());
		// 排除配置
		weixinInterceptor.excludePathPatterns("/auth.htm");
		weixinInterceptor.excludePathPatterns("/*/bind.htm");
		weixinInterceptor.excludePathPatterns("/extend/*.htm");
		weixinInterceptor.excludePathPatterns("/static/**");
        // 拦截配置
		weixinInterceptor.addPathPatterns("/**");
		
		//
		InterceptorRegistration tokenInterceptor = registry.addInterceptor(getTokenInterceptor());
		// 排除配置
		tokenInterceptor.excludePathPatterns("/static/**");
        // 拦截配置
		tokenInterceptor.addPathPatterns("/**");
	} 

}
